package com.yun.util.yun.utils.password;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;

public class Base64Coder {
	
	private static final String ENCODING = "UTF-8";
    
    /**
     * 一般Base64加密
     */
    public static String encode(String data) throws UnsupportedEncodingException{
        byte[] encodedByte = Base64.encodeBase64(data.getBytes(ENCODING));
        return new String(encodedByte, ENCODING);
    }
    
    /**
     * Base64解密
     */
    public static String decode(String data) throws UnsupportedEncodingException{
        byte[] decodedByte = Base64.decodeBase64(data.getBytes(ENCODING));
        return new String(decodedByte, ENCODING);
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        String a = "admin@123456";
        System.out.println(encode(a));
        System.out.println(decode(encode(a)));
    }
}
